import request from '@/utils/request'

const BASE = '/v1/vehicle'

// 获取司机列表
export const getDriverList = (params) => {
  return request({
    url: `${BASE}/driver`,
    method: 'GET',
    params
  })
}

// 获取车辆列表
export const getVehiclesList = (params, companyId) => {
  const header = {}
  if (companyId) {
    header['company-id'] = companyId
  }
  return request({
    url: `${BASE}`,
    method: 'GET',
    params,
    headers: {
      ...header
    }
  })
}

export const getVehiclesListNoLogin = (params, companyId) => {
  const header = {}
  if (companyId) {
    header['company-id'] = companyId
  }
  return request({
    url: `${BASE}/gps`,
    method: 'GET',
    params,
    headers: {
      ...header
    }
  })
}

// 获取用车记录
export const getUseCarRecordList = (params) => {
  return request({
    url: `${BASE}/dispatch`,
    method: 'GET',
    params
  })
}

// 新建派车单
export const addUseVehicle = (data) => {
  return request({
    url: `${BASE}/dispatch`,
    method: 'POST',
    data
  })
}

// 审核用户提交的派车单
export const examineUseVehicle = (params, id) => {
  return request({
    url: `${BASE}/dispatch/examine/${id}`,
    method: 'PUT',
    params
  })
}

// 司机确认收到派车单
export const driverConfirmVehicle = (params) => {
  return request({
    url: `${BASE}/confirm/car/${params.id}`,
    method: 'PUT',
    params
  })
}

// 司机开始用车
export const driverUseCarStart = (params) => {
  return request({
    url: `${BASE}/start/car/${params.id}`,
    method: 'PUT',
    params
  })
}

// 司机结束用车
export const driverUseCarEnd = (params) => {
  return request({
    url: `${BASE}/end/car/${params.id}`,
    method: 'PUT',
    params
  })
}

// 新增车辆资源
export const addVehicleResource = (data) => {
  return request({
    url: `${BASE}/resource`,
    method: 'POST',
    data
  })
}

// 修改车辆资源
export const editVehicleResource = (params) => {
  return request({
    url: `${BASE}/resource/${params.id}`,
    method: 'PUT',
    params
  })
}

// 删除车辆资源
export const deleteVehicleResource = (id) => {
  return request({
    url: `${BASE}/resource/${id}`,
    method: 'DELETE'
  })
}

// 添加司机
export const addDriver = (data) => {
  return request({
    url: `${BASE}/driver/resource`,
    method: 'POST',
    data
  })
}

// 修改司机信息
export const editDriver = (params) => {
  return request({
    url: `${BASE}/driver/resource/${params.id}`,
    method: 'PUT',
    params
  })
}

// 删除司机
export const deleteDriver = (id) => {
  return request({
    url: `${BASE}/driver/resource/${id}`,
    method: 'DELETE'
  })
}

// 获取派车详情
export const getUseCarRecordDetail = (id) => {
  return request({
    url: `${BASE}/dispatch/${id}`,
    method: 'GET'
  })
}

// 获取当前时间以及之后的用车记录
export const getTodayAndAfterVehicleRecord = () => {
  return request({
    url: `${BASE}/today/vehicle`,
    method: 'GET'
  })
}

// 获取未设置为司机的用户列表
export const getNotSetDriverUsers = (params) => {
  return request({
    url: `${BASE}/not/set/driver`,
    method: 'GET',
    params
  })
}

// 获取车辆类型
export const getVehicleType = (params) => {
  return request({
    url: `${BASE}/type`,
    method: 'GET',
    params
  })
}

// 创建车辆类型
export const createVehicleType = (data) => {
  return request({
    url: `${BASE}/type`,
    method: 'POST',
    data
  })
}

// 修改车辆类型
export const editVehicleType = (params) => {
  return request({
    url: `${BASE}/type/${params.id}`,
    method: 'PUT',
    params
  })
}

// 删除车辆类型
export const deleteVehicleType = (id) => {
  return request({
    url: `${BASE}/type/${id}`,
    method: 'DELETE'
  })
}

// 删除派车单
export const deleteVehicleRecords = (id) => {
  return request({
    url: `${BASE}/dispatch/${id}`,
    method: 'DELETE'
  })
}

// 撤销派车单
export const cancelVehicleRecords = (id) => {
  return request({
    url: `${BASE}/dispatch/cancel/${id}`,
    method: 'POST'
  })
}

// 管理员修改派车单
export const editCarUseByAdmin = (params) => {
  return request({
    url: `${BASE}/dispatch/${params.id}`,
    method: 'PUT',
    params
  })
}

export const getVehicleScheduleList = (params) => {
  return request({
    url: `v1/vehicle/car/dispatch/record`,
    method: 'GET',
    params
  })
}

export const getVehicleApproval = (params) => {
  return request({
    url: `v1/vehicle/private/car`,
    method: 'GET',
    params
  })
}
